<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>已发布游记管理</title>
    <#include "../common/header.ftl"/>
    <#include "../common/page.ftl"/>
    <script>
      $(function () {
          // 查看游记信息
          $('.lookBtn').click(function() {
              var travelId =  $(this).data('id');
              $.get('/travel/getTravelById.do',{travelId:travelId},function (data) {
                  $('#showModal .modal-body').html(data.content);
              });
              $('#showModal').modal('show');
          });
          // 取消发布
          $('.cancleBtn').click(function() {
              var id = $(this).data('id');
              var state = $(this).data('state');
              // 发送请求修改游记状态
              $.post('/travel/changeState.do',{id:id,state:state},function (data) {
                  if(data.success){
                      $.messager.confirm("温馨提示","操作成功",function () {
                          window.location.reload();
                      })
                  }else {
                      $.messager.alert("温馨提示","操作失败");
                  }
              });
          });

            // 推荐数据回显
          $('.pushBtn').click(function() {
              var data = $(this).data('json');
              $('#editForm')[0].reset();
              $('#editForm img').attr('src','');
              if(data){
                  $('#editForm input[name="title"]').val(data.title);
                  $('#editForm input[name="travel.id"]').val(data.id);
                  $('#editForm input[name="coverUrl"]').val(data.coverUrl);
                  $('#editForm img').attr('src',data.coverUrl);
              }
              $('#editModal').modal('show');
          });
          // 图片更换是回显
          $('#editForm input[name="file"]').change(function () {
              // 创建文件读取器对象
              var read = new FileReader();
              // 读取文件内容
              read.readAsDataURL(this.files[0]);
              // 将用户选择的图片渲染到页面
              $(read).load(function () {
                  $('#editForm img').attr('src',read.result);
              });
              // $('#editForm img').attr('src',window.URL.createObjectURL(this.files[0]));
          });
          // 推荐操作
          $('.btn_submit').click(function () {
              // 插件原因,不能在循环中return false,没效果
              var flag = false;
              $('#editForm').ajaxSubmit({
                  beforeSubmit: function (params) {
                      $.each(params,function (index, value) {
                          // 遍历表单中所有的参数,找到type
                          if($(value).attr("name")==="type"){
                              // 其对应的值如果是-1说明用户没有选择推荐类型
                              if($(value).attr("value") == -1){
                                  flag = true;
                              }
                          }
                      })
                      if(flag){
                          $.messager.alert("温馨提示","请选择推荐类型!");
                          return false;
                      }
                  },
                  success: function(data){
                      if(data.success){
                          window.location.reload();
                      }
                  }
              });
          });
      });
    </script>
    <style type="text/css">
        #showModal img {
            width: 100%;
        }
        #showModal .modal-body{
            max-height: 600px;
            overflow-y: auto;
        }
    </style>
</head>

<body>
<div class="container">
<#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
		<#assign currentMenu = "releaseList" />
				<#include "../common/menu.ftl" />
        </div>
        <div class="col-sm-9">
            <div class="page-header">
                <h3>已发布游记管理</h3>
            </div>
            <div class="row">
                <!-- 提交分页的表单 -->
                <form id="searchForm" class="form-inline" method="post" action="/travel/releaseList.do">
                    <input type="hidden" name="currentPage" id="currentPage" value="1"/>
                    <div class="form-group">
                    </div>
                    <div class="form-group">
                        <label>关键字</label>
                        <input class="form-control" type="text" name="keyword" placeholder="请输入标题/昵称"  value="${(qo.keyword)!''}">
                    </div>
                    <div class="form-group">
                        <button id="query" type="button" class="btn btn-success"><i class="icon-search"></i> 查询</button>
                    </div>
                </form>
            </div>
            <div class="row">
                <table class="table">
                    <thead>
                    <tr>
                        <th>标题</th>
                        <th>封面</th>
                        <th>地区</th>
                        <th>作者</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
					<#list result.list as vo>
                    <tr>
                        <td>${vo.title!}</td>
                        <td><img src="${vo.coverUrl!}" style="width: 60px" alt=""></td>
                        <td>${vo.place.name!}</td>
                        <td>${vo.author.nickName!}</td>
                        <td>${vo.stateDisplay}</td>
                        <td>
                            <a href="javascript:;" class="btn btn-danger cancleBtn" data-state="1" data-id="${vo.id}">取消发布</a>
                            <a href="javascript:;" class="btn btn-primary lookBtn" data-id="${vo.id}">查看文章</a>
                            <a href="avascript:;" class="btn btn-success pushBtn" data-json='${(vo.jsonString)!}'>推荐</a>
                        </td>
                    </tr>
					</#list>
                    </tbody>
                </table>

                <div style="text-align: center;">
                    <ul id="pagination" class="pagination"></ul>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="showModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">游记详情</h4>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">确定</button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">编辑/添加</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/travelCommend/saveOrUpdate.do" method="post" id="editForm" enctype="multipart/form-data">
                    <input type="hidden" value="" name="id">
                    <input type="hidden" value="" name="travel.id">
                    <div class="form-group" id="parentDiv">
                        <label class="col-sm-3 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">副标题 ：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="subTitle">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">封面 ：</label>
                        <div class="col-sm-6">
                            <img  style="width: 250px;"/>
                            <input type="file" class="form-control" name="file">
                            <input type="hidden" class="form-control" name="coverUrl">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">推荐日期 ：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="schedule" onclick="WdatePicker()" readonly>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">推荐类型：</label>
                        <div class="col-sm-6">
                            <select name="type" class="form-control">
                                <option value="-1">推荐类型</option>
                                <option value="0">周推荐</option>
                                <option value="1">月推荐</option>
                                <option value="2">攻略推荐</option>
                            </select>
                        </div><br>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn_submit">保存</button>
                <button type="button" class="btn btn-danger" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>